package com.googlecode.iiddefecttracker.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.googlecode.iiddefecttracker.domain.Defect;
import com.googlecode.iiddefecttracker.service.DefectService;

/**
 * I am {@link Controller} for defects page.
 */
public class DefectController implements Controller {
    
    private final DefectService defectService;
    
    public DefectController(final DefectService projectService) {
        this.defectService = projectService;
    }
    
    public ModelAndView handleRequest(final HttpServletRequest request,
            final HttpServletResponse response) throws Exception {
        
        final List<Defect> defectsFound = defectService.findAllDefects();
        
        final Map<String, Object> defectsListPageModel = new HashMap<String, Object>();
        defectsListPageModel.put("defects", defectsFound);
        
        return new ModelAndView("defectsList", "model", defectsListPageModel);
    }
    
}
